<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,layui,,dtvalidate'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
    <input type="hidden" value="${status}" id="status">


    <div class="row">
        <div class="col-sm-12">
            <!-- START 右侧数据 -->
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">状态:</label>
                            <div class="col-sm-2">
                                <select  id="createPlanStatusTwo" name="createPlanStatus"  class="form-control">
                                    <option value="">请选择</option>
                                    <option value="0">全部</option>
                                    <option value="3">已发运</option>
                                    <option value="4">已开船</option>
                                    <option value="5">已清关</option>
                                    <option value="6">已送货</option>
                                    <option value="7">已入库</option>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">柜号:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createPlanNo" name="createPlanNo" placeholder="请输入柜号" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">SKU:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createSku" name="createSku" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">shipmentId:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createShipmentId" name="createShipmentId" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">会计期间:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createPeriod" name="createPeriod" placeholder="请选择会计期间" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">Listing:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createListing" name="createListing" placeholder="请选择Listing" class="form-control">
                            </div>

                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                        </div>
                    </form>
                </div>
            </div>
            <!-- END 右侧数据 -->
        </div>
    </div>
    <form>
        <div id="toolbar" class="btn-group">

            <a class="export-btn btn btn-sm btn-primary"><i class="fa fa-paste" aria-hidden="true"></i> 导出当前数据</a>
            <a class="receive-btn btn btn-sm btn-warning"><i class="fa fa-upload" aria-hidden="true"></i> 一键收货</a>
            <input type="hidden" id="userRealname" value="${user.userRealname}">
        </div>
    </form>
    <div class="wrapper wrapper-content">

            <!-- START 数据表格 -->
            <table id="planTable"
                   data-toolbar="#toolbar"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-url="/sea/physical/customs/findByCnd.do?createPlanStatus=${status}"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
    </div>

<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">日期</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="recordOperateDate" name="recordOperateDate" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">备注</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="recordText" name="recordText" value="" class="form-control">
                </div>
                <div id="id" hidden="hidden"></div>
                <div id="createPlanStatus" hidden="hidden"></div>

            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>


    <div id="receive_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
        <!-- START 内容部分 -->
        <div class="container" >
            <form class="form-horizontal" id="info-receive-form" method="post" autocomplete="off" style="margin: auto">
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-sm-2" style="max-width: 100px">日期</label>
                    <div class="col-sm-6" style="max-width: 300px">
                        <input type="text" id="receiveDate" name="receiveDate" value="" class="form-control">
                    </div>
                </div>

                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-sm-7" style="max-width: 100px"></label>
                    <button type="button" class="save-receive-btn btn btn-primary">
                        <i class="fa fa-save"></i> 保存
                    </button>
                </div>
            </form>
        </div>
        <!-- END 内容部分 -->
    </div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui'}){}%>
<script>
    var $planTable = $('#planTable');
    laydate.render({
        elem: '#recordOperateDate',
        type: 'date',
        trigger: 'click', //修改触发方式
        format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#receiveDate',
        type: 'date',
        trigger: 'click', //修改触发方式
        format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#createPeriod',
        type: 'month'
        ,trigger: 'click'
    });
    $(function () {
        // START 表格配置
        $planTable.bootstrapTable({
            pageList: [10, 15, 20, 2000],
            pageSize:10,
            detailView: true,
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜型',
                    field: 'createPlanCabinetName',
                    align: 'center',
                    valign: 'middle'
                }, {
                    title: '运输',
                    field: 'createPlanTransport',
                    align: 'center',
                    valign: 'middle'

                },
                {
                    title: '国家',
                    field: 'createPlanCountry',
                    align: 'center',
                    valign: 'middle'

                },
                {
                    title: '装柜地点',
                    field: 'createPlanPlace',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '装柜时间',
                    field: 'createPlanPlaceDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发运时间1',
                    field: 'despatchDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '开船时间',
                    field: 'driveBoatDate',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if (v == null) {
                            return '';
                        }
                        v = v.substr(0, 11);
                        return v;
                    }
                },
                {
                    title: '清关时间',
                    field: 'clearDate',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if (v == null) {
                            return '';
                        }
                        v = v.substr(0, 11);
                        return v;
                    }
                },
                {
                    title: '送货时间',
                    field: 'sendDate',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if (v == null) {
                            return '';
                        }
                        v = v.substr(0, 11);
                        return v;
                    }
                },
                {
                    title: '出运港',
                    field: 'despatchPortName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '目的港',
                    field: 'despatchDestName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '目的港仓库',
                    field: 'despatchStoreName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '运费',
                    field: 'despatchFreight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '币种',
                    field: 'despatchCurrency',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总件数',
                    field: 'createPlanTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总箱数',
                    field: 'createPlanBox',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总体积',
                    field: 'createPlanVolume',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '小件数',
                    field: 'createPlanNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总毛重',
                    field: 'createWeightTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总净重',
                    field: 'createKgTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '清关金额',
                    field: 'createCustomMoney',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '总预计关税',
                    field: 'createCustomTax',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '退税',
                    field: 'isRefused',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(v==0){
                            return '否';
                        }else{
                            return '是';
                        }
                    }
                },
                {
                    title: '状态',
                    field: 'createPlanStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        var result='';
                        switch (v) {
                            case 1:
                                result='未处理';
                                break;
                            case 2:
                                result='已分配';
                                break;
                            case 3:
                                result='已发运';
                                break;
                            case 4:
                                result='已开船';
                                break;
                            case 5:
                                result='已清关';
                                break;
                            case 6:
                                result='已送货';
                                break;
                            case 7:
                                result='已入库';
                                break;
                            default:
                               result='';
                        }
                        return result;
                    }
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                var status=$("#status").val();
                if(status=='3'){
                    $('#planTable').bootstrapTable('hideColumn', 'driveBoatDate');
                    $('#planTable').bootstrapTable('hideColumn', 'clearDate');
                    $('#planTable').bootstrapTable('hideColumn', 'sendDate');
                }
                if(status=='4'){
                    $('#planTable').bootstrapTable('hideColumn', 'despatchDate');
                    $('#planTable').bootstrapTable('hideColumn', 'clearDate');
                    $('#planTable').bootstrapTable('hideColumn', 'sendDate');
                }
                if(status=='5'){
                    $('#planTable').bootstrapTable('hideColumn', 'despatchDate');
                    $('#planTable').bootstrapTable('hideColumn', 'driveBoatDate');
                    $('#planTable').bootstrapTable('hideColumn', 'sendDate');
                }
                if(status=='6'){
                    $('#planTable').bootstrapTable('hideColumn', 'despatchDate');
                    $('#planTable').bootstrapTable('hideColumn', 'driveBoatDate');
                    $('#planTable').bootstrapTable('hideColumn', 'clearDate');
                }

                $('.detail-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['700px','500px'],
                        content: ['/sea/physical/record/main.do?createId='+id, 'yes']
                    });
                });
                $('.send-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    var status=$(this).attr('data-status');
                    $('#id').val(id);
                    $('#createPlanStatus').val(status);
                    layer.open({
                        type:1,
                        title:'确认日期',
                        area:['600px','250px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })
                });

            },onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });

        //初始化子表格(无线循环)
        function InitSubTable (index, row, $detail) {
            var parentId = row.createId;
            var cur_table = $detail.html('<table></table>').find('table');
            $(cur_table).bootstrapTable({
                url: '/sea/physical/despatch/findByCreateId',
                method: 'get',
                clickToSelect: true,
                queryParams: { createId: parentId},
                ajaxOptions: { id: parentId },
                clickToSelect: true,
                //height: 500,
                detailView: false,//父子表
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        field: 'createShipmentId',
                        title: 'ShipmentId'
                    },
                    {
                        field: 'createSku',
                        title: 'SKU'
                    },{
                        field: 'createFnSku',
                        title: 'FNSKU'
                    },{
                        field: 'createListing',
                        title: 'Listing'
                    },{
                        field: 'despatchStoreName',
                        title: '仓库'
                    },{
                        field: 'productNumber',
                        title: '流水号'
                    },{
                        field: 'productName',
                        title: '产品名称'
                    },{
                        field: 'productEnName',
                        title: '名称(英文)'
                    },{
                        field: 'productColorName',
                        title: '颜色'
                    },{
                        field: 'productCm',
                        title: '尺码(CM)'
                    },{
                        field: 'productInch',
                        title: '尺码(INCH)'
                    },{
                        field: 'createNumber',
                        title: '数量'
                    },{
                        field: 'productPackQuan',
                        title: '装箱量'
                    },{
                        field: 'createBoxNumber',
                        title: '箱数'
                    },{
                        field: 'productContainCount',
                        title: '内含件数'
                    },{
                        field: 'createNumberTotal',
                        title: '总件数'
                    },{
                        field: 'createSupplierName',
                        title: '供应商'
                    },{
                        field: 'createWeightTotal',
                        title: '总毛重'
                    },{
                        field: 'createKgTotal',
                        title: '总净重'
                    },{
                        field: 'createVolumeTotal',
                        title: '总体积'
                    },{
                        field: 'createCustomMoney',
                        title: '申报金额'
                    },{
                        field: 'createCustomRate',
                        title: '清关税率'
                    },{
                        field: 'createCustomTax',
                        title: '预估税金'
                    },
                    {
                        title: '单位',
                        field: 'productUnit',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '报关名称',
                        field: 'productDeclarationName',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'createRemark',
                        title: '备注'
                    }],
                onLoadSuccess : function(){

                }
            });
        };
    });
    // 条件查询
    $('.search-btn').on('click',function () {
        $planTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/physical/customs/findByCnd.do?'+$('#search-form').serialize() });
    });
    // 操作菜单
    function optFormatter(value,row){
        var content = '';
        var status=$("#status").val();
        console.log(row.createPlanStatus+" "+status);
        if(row.createPlanStatus==3 ){
            content += '&nbsp;<button class="send-btn btn btn-xs btn-success" data-status="'+row.createPlanStatus+'" data-val="'+row.createId+'" title="开船"><i class="fa fa-check-square-o"></i> 开船</button>';
        }
        if(row.createPlanStatus==4 ){
            content += '&nbsp;<button class="send-btn btn btn-xs btn-success" data-status="'+row.createPlanStatus+'" data-val="'+row.createId+'" title="清关"><i class="fa fa-check-square-o"></i> 清关</button>';
        }
        if(row.createPlanStatus==5){
            content += '&nbsp;<button class="send-btn btn btn-xs btn-success" data-status="'+row.createPlanStatus+'" data-val="'+row.createId+'" title="送货"><i class="fa fa-check-square-o"></i> 送货</button>';
        }
        if(row.createPlanStatus==6 ){
            content += '&nbsp;<button class="send-btn btn btn-xs btn-success" data-status="'+row.createPlanStatus+'" data-val="'+row.createId+'" title="入库"><i class="fa fa-check-square-o"></i> 入库</button>';
        }
        content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="'+row.createId+'" title="查看记录"> 查看记录</button>';
        return content;
    }

    //提交表单
    $('.save-btn').on('click',function(){
        var id=$("#id").val();
        //清关计划
        layer.confirm('确定要修改当前计划？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var status=$("#createPlanStatus").val();
            var recordOperateDate=$("#recordOperateDate").val();
            if(recordOperateDate==''){
                parent.layer.msg('请选择日期！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/physical/customs/send.do',{id:id,createPlanStatus:status,recordOperateDate:recordOperateDate,recordText:$("#recordText").val()},function(data){
                if( data.ok ){
                    $planTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:5000,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });
    $('.export-btn').on('click',function () {
        var selDatas = $planTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要导出的',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var ids = [],names = [];
            $.each(selDatas,function(i,d){
                ids.push(d.createId);
            });
            ids = ids.join(',');
            window.location.href='/sea/physical/customs/export.do?ids='+ids;
        }
    });

    $(".save-receive-btn").on('click',function () {
        var receiveDate=$("#receiveDate").val();
        if(receiveDate==null || receiveDate==''){
            layer.msg('请选择收货日期！',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else {
            var selDatas = $planTable.bootstrapTable('getSelections');
            var userRealname = $("#userRealname").val();
            var index = layer.load();
            var ids = [], names = [];
            $.each(selDatas, function (i, d) {
                ids.push(d.createId);
            });
            ids = ids.join(',');
            $.post('/sea/physical/customs/receive.do', {
                ids: ids,
                userRealname: userRealname,
                receiveDate: $("#receiveDate").val()
            }, function (data) {
                if (data.ok) {

                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                        }});

                } else {
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                        }});
                }
            });
        }
    });
    $('.receive-btn').on('click',function () {
        var selDatas = $planTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要收货的的柜号',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            layer.open({
                type:1,
                title:'收货日期',
                area:['600px','250px'],
                skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose:false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content:$('#receive_window')
            })


        }
    });
</script>
</body>
</html>
